Produced by Araxis Merge on 2021-05-13 09:08:40 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | /Applications/Ampps/www/Porto 3.2.2/Theme Files/Magento 2.x/Porto Theme/app/code/Smartwave/Filterproducts/Block | BestsellersList.php | 2017-02-04 19:03:02 +0000 |
| 2 | 2021-05-13 09:08:40 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 105 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | <?php | |||||
| 2 | ||||||
| 3 | namespace Smartwave\Filterproducts\Block; | |||||
| 4 | ||||||
| 5 | class BestsellersList extends \Magento\Catalog\Block\Product\AbstractProduct { | |||||
| 6 | ||||||
| 7 | protected $_catalogProductVisibility; | |||||
| 8 | ||||||
| 9 | protected $_productCollectionFactory; | |||||
| 10 | ||||||
| 11 | protected $_categoryFactory; | |||||
| 12 | ||||||
| 13 | protected $urlHelper; | |||||
| 14 | ||||||
| 15 | protected $_resource; | |||||
| 16 | ||||||
| 17 | public function __construct( | |||||
| 18 | \Magento\Catalog\Block\Product\Context $context, | |||||
| 19 | \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, | |||||
| 20 | \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, | |||||
| 21 | \Magento\Catalog\Model\CategoryFactory $categoryFactory, | |||||
| 22 | \Magento\Framework\Url\Helper\Data $urlHelper, | |||||
| 23 | \Magento\Framework\App\ResourceConnection $resource, | |||||
| 24 | array $data = [] | |||||
| 25 | ) { | |||||
| 26 | $this->_categoryFactory = $categoryFactory; | |||||
| 27 | $this->_productCollectionFactory = $productCollectionFactory; | |||||
| 28 | $this->_catalogProductVisibility = $catalogProductVisibility; | |||||
| 29 | $this->urlHelper = $urlHelper; | |||||
| 30 | $this->_resource = $resource; | |||||
| 31 | ||||||
| 32 | parent::__construct($context, $data); | |||||
| 33 | } | |||||
| 34 | ||||||
| 35 | public function getProducts() { | |||||
| 36 | $count = $this->getProductCount(); | |||||
| 37 | $category_id = $this->getData("category_id"); | |||||
| 38 | $collection = $this->_productCollectionFactory->create(); | |||||
| 39 | $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds()); | |||||
| 40 | $collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter(); | |||||
| 41 | if(!$category_id) { | |||||
| 42 | $category_id = $this->_storeManager->getStore()->getRootCategoryId(); | |||||
| 43 | } | |||||
| 44 | $category = $this->_categoryFactory->create()->load($category_id); | |||||
| 45 | $connection = $this->_resource->getConnection(); | |||||
| 46 | if(isset($category) && $category) { | |||||
| 47 | $collection->addMinimalPrice() | |||||
| 48 | ->addFinalPrice() | |||||
| 49 | ->addTaxPercents() | |||||
| 50 | ->addAttributeToSelect('name') | |||||
| 51 | ->addAttributeToSelect('image') | |||||
| 52 | ->addAttributeToSelect('small_image') | |||||
| 53 | ->addAttributeToSelect('thumbnail') | |||||
| 54 | ->addAttributeToSelect($this->_catalogConfig->getProductAttributes()) | |||||
| 55 | ->addUrlRewrite() | |||||
| 56 | ->addAttributeToFilter('is_saleable', 1, 'left') | |||||
| 57 | ->addCategoryFilter($category); | |||||
| 58 | } else { | |||||
| 59 | $collection->addMinimalPrice() | |||||
| 60 | ->addFinalPrice() | |||||
| 61 | ->addTaxPercents() | |||||
| 62 | ->addAttributeToSelect('name') | |||||
| 63 | ->addAttributeToSelect('image') | |||||
| 64 | ->addAttributeToSelect('small_image') | |||||
| 65 | ->addAttributeToSelect('thumbnail') | |||||
| 66 | ->addAttributeToSelect($this->_catalogConfig->getProductAttributes()) | |||||
| 67 | ->addUrlRewrite() | |||||
| 68 | ->addAttributeToFilter('is_saleable', 1, 'left'); | |||||
| 69 | } | |||||
| 70 | ||||||
| 71 | $collection->getSelect() | |||||
| 72 | ->joinLeft(['soi' => $connection->getTableName('sales_order_item')], 'soi.product_id = e.entity_id', ['SUM(soi.qty_ordered) AS ordered_qty']) | |||||
| 73 | ->join(['order' => $connection->getTableName('sales_order')], "order.entity_id = soi.order_id",['order.state']) | |||||
| 74 | ->where("order.state <> 'canceled' and soi.parent_item_id IS NULL AND soi.product_id IS NOT NULL") | |||||
| 75 | ->group('soi.product_id') | |||||
| 76 | ->order('ordered_qty DESC') | |||||
| 77 | ->limit($count); | |||||
| 78 | ||||||
| 79 | return $collection; | |||||
| 80 | } | |||||
| 81 | ||||||
| 82 | public function getAddToCartPostParams(\Magento\Catalog\Model\Product $product) | |||||
| 83 | { | |||||
| 84 | $url = $this->getAddToCartUrl($product); | |||||
| 85 | return [ | |||||
| 86 | 'action' => $url, | |||||
| 87 | 'data' => [ | |||||
| 88 | 'product' => $product->getEntityId(), | |||||
| 89 | \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => | |||||
| 90 | $this->urlHelper->getEncodedUrl($url), | |||||
| 91 | ] | |||||
| 92 | ]; | |||||
| 93 | } | |||||
| 94 | ||||||
| 95 | public function getLoadedProductCollection() { | |||||
| 96 | return $this->getProducts(); | |||||
| 97 | } | |||||
| 98 | ||||||
| 99 | public function getProductCount() { | |||||
| 100 | $limit = $this->getData("product_count"); | |||||
| 101 | if(!$limit) | |||||
| 102 | $limit = 10; | |||||
| 103 | return $limit; | |||||
| 104 | } | |||||
| 105 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.